package t;
import java.util.Scanner;
import static java. lang.Math.max;
public class t2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] m = new int[n];
        for (int i = 0; i < n; i++) m[i] = scanner.nextInt();
        int x = m[0], s = 0;
        for (int i = 0; i < n; i++) {
            s = max(s + m[i], m[i]);
            x = max(x, s);
        }
        System.out.println(x);
    }
}
